<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="page[parent::pages]">
		<xsl:param name="url_prefix" select="$module_url"/>
		<xsl:variable name="gp">
			<xsl:for-each select="$gparams">
				<xsl:choose>
					<xsl:when test="position() = 1">?</xsl:when>
					<xsl:otherwise>&amp;</xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="@name"/>
				<xsl:text>=</xsl:text>
				<xsl:value-of select="@value"/>
			</xsl:for-each>
		</xsl:variable>
		<!--$fp будет содержать все фолдеры, кроме последнего, если он начинается с "page-" -->
		<xsl:variable name="fp">
			<xsl:for-each select="$fparams">
				<xsl:if test="substring(text(), 0, 6) != 'page-'">
					<xsl:choose>
						<xsl:when test="position() = 1">/</xsl:when>
						<xsl:otherwise>/</xsl:otherwise>
					</xsl:choose>
					<xsl:value-of select="text()"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
		<xsl:choose>
			<xsl:when test="@type='prev'">
				<xsl:choose>
					<xsl:when test="@number = 1">
						<a href="{$url_prefix}{$fp}/{$gp}">&#8592;</a>
					</xsl:when>
					<xsl:otherwise>
						<a href="{$url_prefix}{$fp}/page-{@number}/{$gp}">&#8592;</a>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="@type='current'">
				<b>
					<xsl:value-of select="@number"/>
				</b>
			</xsl:when>
			<xsl:when test="@type='delimeter'">
				<span>...</span>
			</xsl:when>
			<xsl:when test="@type='page'">
				<a href="{$url_prefix}{$fp}/page-{@number}/{$gp}">
					<xsl:if test="@number = 1">
						<xsl:attribute name="href">
							<xsl:value-of select="concat($url_prefix, $fp, '/', $gp)"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="@number"/>
				</a>
			</xsl:when>
			<xsl:when test="current()[@type='next']">
				<a href="{$url_prefix}/page-{@number}/{$gp}">&#8594;</a>
			</xsl:when>
		</xsl:choose>
		<xsl:text> </xsl:text>
	</xsl:template>
</xsl:stylesheet>
